home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BTGETCUR.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  84 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btgetcur.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STRING
  11. #include <string.h>
  12. #endif
  13.  
  14. /* library headers */
  15. #include <blkio.h>
  16.  
  17. /* local headers */
  18. #include "btree_.h"
  19.  
  20. /*man---------------------------------------------------------------------------
  21. NAME
  22.      btgetcur - get btree cursor
  23.  
  24. SYNOPSIS
  25.      #include <btree.h>
  26.  
  27.      int btgetcur(btp, btposp)
  28.      btree_t *btp;
  29.      btpos_t *btposp;
  30.  
  31. DESCRIPTION
  32.      The btgetcur function gets the current cursor position for btree
  33.      btp and copies it to btposp.  A btree position saved with
  34.      btgetcur can be used to reposition to a key using btsetcur.  It
  35.      is important to remember that a btree position is not valid after
  36.      an insertion, deletion, or unlock.
  37.  
  38.      btgetcur will fail if one or more of the following is true:
  39.  
  40.      [EINVAL]       btp is not a valid btree pointer.
  41.      [EINVAL]       btposp is the NULL pointer.
  42.      [BTELOCK]      btp is not locked.
  43.      [BTENOPEN]     btp is not open.
  44.  
  45. SEE ALSO
  46.      btsetcur.
  47.  
  48. DIAGNOSTICS
  49.      Upon successful completion, a value of 0 is returned.  Otherwise,
  50.      a value of -1 is returned, and errno set to indicate the error.
  51.  
  52. ------------------------------------------------------------------------------*/
  53. #ifdef AC_PROTO
  54. int btgetcur(btree_t *btp, btpos_t *btposp)
  55. #else
  56. int btgetcur(btp, btposp)
  57. btree_t *btp;
  58. btpos_t *btposp;
  59. #endif
  60. {
  61.     /* validate arguments */
  62.     if (!bt_valid(btp) || btposp == NULL) {
  63.         errno = EINVAL;
  64.         return -1;
  65.     }
  66.  
  67.     /* check if not open */
  68.     if (!(btp->flags & BTOPEN)) {
  69.         errno = BTENOPEN;
  70.         return -1;
  71.     }
  72.  
  73.     /* check locks */
  74.     if (!(btp->flags & BTLOCKS)) {
  75.         errno = BTELOCK;
  76.         return -1;
  77.     }
  78.  
  79.     /* get current position */
  80.     memcpy(btposp, &btp->cbtpos, sizeof(*btposp));
  81.  
  82.     return 0;
  83. }
  84.